package gretha.Jtables.utils;

import gretha.Jtables.JTableMassif;
import gretha.panels.CreationScenario;
import gretha.panels.PanelListeMassifs;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

public class boutonSupprimerCellEditor extends AbstractCellEditor implements
		TableCellEditor, ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6885791162797881337L;
	private JButton bouton;
	private JTableMassif tblm;
	private PanelListeMassifs panel;

	public boutonSupprimerCellEditor(JTableMassif tbl, PanelListeMassifs pan) {
		super();

		bouton = new JButton("Supprimer");
		bouton.setActionCommand("Supprimer");
		bouton.addActionListener(this);
		tblm = tbl;
		panel = pan;
	}

	@Override
	public Object getCellEditorValue() {
		return "Supprimer";
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		tblm.supprimerLigne(tblm.getSelectedRow());
		PanelListeMassifs.parent.setListeDesMassifsDuScenario(tblm.getDonnees());
		((CreationScenario) panel.getParent()).rafraichir();

	}

	@Override
	public Component getTableCellEditorComponent(JTable arg0, Object arg1,
			boolean arg2, int arg3, int arg4) {
		return bouton;
	}

}
